import { View } from "../../../../mvc/core/View";
import { ShopInfo } from "../../../resource/info/ShopInfo";
import { Cache } from "../../../cache/Cache";
import { ItemData } from "../../../resource/info/ItemData";
import { StrengthAddConfig } from "../../../resource/StrengthAddConfig";
import { EToNAddType } from "../../../../../Message/Public/EToNAddType";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ShopMeritItem } from "./ShopMeritItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { StrengthenAddInfo } from "../../../resource/info/StrengthenAddInfo";
type int = number;
//class ShopMeritInfoPanel
    
    export  class ShopMeritInfoPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public set shopInfo(arg1: ShopInfo)
        {
            this._shopInfo = arg1;
            return;
        }

        public updateByMedalLevel(): void
        {
            var loc3=0;
            var loc1=Cache.instance.role.entityInfo.career;
            var loc2=Cache.instance.role.medalCode;
            if (loc2 > 0) 
            {
                this._medalItemData = new ItemData(loc2);
                loc3 = this._medalItemData.itemInfo.item.itemLevel;
            }
            else 
            {
                loc3 = 1;
            }
            this._currentShopItemInfo = this.getShopItemInfoByLevel(loc3);
            this._nextShopItemInfo = this.getShopItemInfoByLevel(loc3 + 1);
            this._currentAddInfo = StrengthAddConfig.instance.getStrengthenAddInfo(EToNAddType._EToNAddTypeMedal, loc1, loc3);
            this._nextAddInfo = StrengthAddConfig.instance.getStrengthenAddInfo(EToNAddType._EToNAddTypeMedal, loc1, loc3 + 1);
            this._isDressMax = this._nextAddInfo == null;
            this._nextTipTxt.visible = this._isDressMax;
            this._nextShopMeriteItem.visible = !this._isDressMax;
            this._currentShopMeriteItem.update(this._currentShopItemInfo, this._currentAddInfo);
            this._nextShopMeriteItem.update(this._nextShopItemInfo, this._nextAddInfo, this._currentAddInfo);
            return;
        }

        public updateMerit(arg1: int): void
        {
            this._meritTxt.text = arg1.toString();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 193, 360, this);
            ObjCreate.createBg(0, 364, 193, 67, this);
            ObjCreate.createBg(1, -2, 195, 30, this, ImagesConst.RbListHeader);
            ObjCreate.createBg(35, 400, 120, 20, this, ImagesConst.SelectedBg);
            this._currentShopMeriteItem = new ShopMeritItem(true);
            this._currentShopMeriteItem.x = 5;
            this._currentShopMeriteItem.y = 30;
            this.addChild(this._currentShopMeriteItem);
            ObjCreate.createBg(10, 180, 168, 2, this, ImagesConst.SplitLine);
            this._nextShopMeriteItem = new ShopMeritItem(false);
            this._nextShopMeriteItem.x = 5;
            this._nextShopMeriteItem.y = 183;
            this.addChild(this._nextShopMeriteItem);
            this._meritBg = new Object /* flash.display.Bitmap */();
            this._meritBg.x = 33;
            this._meritBg.y = 375;
            this.addChild(this._meritBg);
            this._meritTxt = ObjCreate.createGTextField("", 35, 402, 120, 20, this, GlobalStyle.textFormat6);
            this._meritTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._meritTxt.text = Cache.instance.role.money.merit.toString();
            this._nextTipTxt = ObjCreate.createGTextField("", 0, 265, 193, 20, this, GlobalStyle.textFormat6);
            this._nextTipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nextTipTxt.htmlText = Language.getString(53095);
            this._nextTipTxt.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.ShopMerit, this.onLoadedHandler);
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            ObjCreate.createBitmap(ImagesConst.ShopMeritMedalLabel, 75, 5, this);
            this._meritBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ShopMeritLabel);
            return;
        }

        /* internal  */getShopItemInfoByLevel(arg1: int): ShopItemInfo
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._shopInfo.items.length) 
            {
                loc1 = this._shopInfo.items[loc2];
                if (loc1.itemInfo.item.itemLevel == arg1) 
                {
                    return loc1;
                }
                ++loc2;
            }
            return null;
        }

        /* internal */ /* var */_currentShopMeriteItem: ShopMeritItem;

        /* internal */ /* var */_nextShopMeriteItem: ShopMeritItem;

        /* internal */ /* var */_meritBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_meritTxt: GTextFiled;

        /* internal */ /* var */_nextTipTxt: GTextFiled;

        /* internal */ /* var */_shopInfo: ShopInfo;

        /* internal */ /* var */_currentShopItemInfo: ShopItemInfo;

        /* internal */ /* var */_nextShopItemInfo: ShopItemInfo;

        /* internal */ /* var */_medalItemData: ItemData;

        /* internal */ /* var */_nextMedalItemData: ItemData;

        /* internal */ /* var */_currentAddInfo: StrengthenAddInfo;

        /* internal */ /* var */_nextAddInfo: StrengthenAddInfo;

        /* internal */ /* var */_isDressMax: Boolean;
    }
